<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录页面</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2.7.14/dist/vue.js"></script>
    <link href="https://cdn.jsdelivr.net/npm/element-ui@2.15.13/lib/theme-chalk/index.min.css" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/element-ui@2.15.13/lib/index.min.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.3/jquery.min.js"></script>
    <style type="text/css">
        .login-wrap {
            box-sizing: border-box;
            width: 100%;
            height: 100%;
            padding-top: 10%;
            background-image: url();
            /* background-color: #112346; */
            background-repeat: no-repeat;
            background-position: center right;
            background-size: 100%;
        }

        .login-container {
            border-radius: 10px;
            margin: 0px auto;
            width: 350px;
            padding: 30px 35px 15px 35px;
            background: #fff;
            border: 1px solid #eaeaea;
            text-align: left;
            box-shadow: 0 0 20px 2px rgba(0, 0, 0, 0.1);
        }

        .title {
            margin: 0px auto 40px auto;
            text-align: center;
            color: #505458;
        }
        #emailCode{
            float: right;
                 }

    </style>
    <style>
        body {
            background-image: url('/背景2.jpg');
        }
    </style>



</head>
<body>
<el-form class="login-container" id="app" >
    <h1 class="title">注册页面</h1>
    <el-form-item lable="请输入注册账号">
        <el-input type="text" v-model="registerForm.username" placeholder="注册账号" autocomplete="off"></el-input>
    </el-form-item>
    <el-form-item lable="请输入注册密码">
        <el-input type="password" v-model="registerForm.password" placeholder="登录密码" autocomplete="off"></el-input>
    </el-form-item>
    <el-form-item lable="请确认密码">
        <el-input type="password" v-model="registerForm.repass" placeholder="确定密码" autocomplete="off"></el-input>
    </el-form-item>
    <el-form-item lable="请输入邮箱" >
        <el-input type="email" v-model="registerForm.email" placeholder="确定邮箱" autocomplete="off"></el-input>
        <el-button  id ="emailCode" type="success" @click="sendEmailCode" style="width: 40%;">邮箱验证码</el-button>
    </el-form-item>
    <el-form-item lable="请输入邮箱验证码">
        <el-input type="captcha" v-model="registerForm.emailCode" placeholder="验证码" autocomplete="off"></el-input>
    </el-form-item>
    <el-form-item lable="请输入手机号">
        <el-input type="tel" v-model="registerForm.tel" placeholder="确定手机号" autocomplete="off"></el-input>
    </el-form-item>
    <el-form-item>
        <el-button type="success" @click="doRegister" style="width: 100%;">注册</el-button>
    </el-form-item>
    <el-row style="text-align: center;margin-top: -10px;">
        <el-link type="primary" @click="doLogin">登录</el-link>
    </el-row>
</el-form>
<script>
    new Vue({
        el: "#app",
        data: {
            registerForm: {
                username: '',
                password: '',
                repass:'',
                email:'',
                emailCode:'',
                tel:''
            }
        },
        methods: {
            doLogin:function(){
                location.href="/login.html"
            },
            doRegister:function(){

                $.post("user/reg",this.registerForm,function (data) {
                    if(data=="ok"){
                        //注册成功,提示并跳转到登录页
                        alert("注册成功,立即前往登录页")
                        location.href="/login.html"
                    }else{
                        //注册失败
                        alert(data);
                    }
                    }
                )
            },
            sendEmailCode:function(){
                // alert("email")
                $.post("user/getEmailCode",{email:this.registerForm.email},function (data){
                      if(data=="ok")  {
                         alert("验证码发送成功，请注意查收")
                      }else{
                         alert(data)
                      }}
                );
            }

        }
    });
</script>
</body>
</html>
